package com.zjp.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import com.zjp.common.core.config.RocketMQConfig;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;


@Component
@RocketMQMessageListener(topic = "${common.topic}", consumerGroup = "${rocketmq.producer.group}", messageModel = MessageModel.CLUSTERING)
public class OrderListener implements RocketMQListener<MessageExt> {
    private static final Logger logger = LoggerFactory.getLogger(OrderListener.class);

    @Value("${common.topic}")
    String topic;
    @Autowired
    RocketMQConfig rocketMQConfig;

    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            String str = StrUtil.str(messageExt.getBody(), StandardCharsets.UTF_8);
            Console.error("发送 时间 " + str + "  消费时间" + DateUtil.now());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
